using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ACME.Northwind.DataTransfer;
using ACME.Northwind.Business.Objects;
using ACME.Northwind.Service.Interfaces;
using Widgetsphere.Core.DataAccess;
using ACME.Northwind.DALProxy.Extensions;

namespace ACME.Northwind.DALProxy
{
	/// <summary>
	/// The service implementation for Supplier object
	/// </summary>
	public partial class SupplierService : ISupplierService
	{
		#region ISupplierService Members

		/// <summary>
		/// Run a selection by the primary key
		/// </summary>
		public SupplierDTO SelectByPrimaryKey(int supplierid)
		{
			SupplierDTO retVal = new SupplierDTO();
			if (!retVal.SelectUsingPK(supplierid)) return null;
			else return retVal;
		}

		/// <summary>
		/// Run the persist for an object
		/// </summary>
		public bool Persist(SupplierDTO dto)
		{
			return (dto.Persist() != null);
		}

		/// <summary>
		/// Run the persist for a list
		/// </summary>
		public bool Persist(List<SupplierDTO> list)
		{
			return list.Persist();
		}

		/// <summary>
		/// Run a selection for all objects
		/// </summary>
		public List<SupplierDTO> RunSelect()
		{
			List<SupplierDTO> retVal = new List<SupplierDTO>();
			retVal.RunSelect();
			return retVal;
		}

		/// <summary>
		/// Run a selection using LINQ
		/// </summary>
		public List<SupplierDTO> RunSelect(string linq)
		{
			List<SupplierDTO> retVal = new List<SupplierDTO>();
			retVal.RunSelect(linq);
			return retVal;
		}

		/// <summary>
		/// Run a paginated selection using LINQ
		/// </summary>
		public PagedQueryResults<SupplierDTO> RunSelect(int pageIndex, int pageSize, bool ascending, string sortColumn, string linq)
		{
			List<SupplierDTO> list = new List<SupplierDTO>();
			string sortOrder;
			if (ascending)
				sortOrder = "ascending";
			else
				sortOrder = "descending";
			return list.RunSelect(pageSize.ToString(), pageIndex.ToString(), sortOrder, sortColumn, linq);
		}

		/// <summary>
		/// Return a list of related Product objects
		/// </summary>
		public List<ProductDTO> GetProductList(SupplierDTO item)
		{
			List<ProductDTO> retval = new List<ProductDTO>();
			retval.SelectBySupplier(item.SupplierId);
			return retval;
		}

		/// <summary>
		/// Delete the specified item
		/// </summary>
		public bool Delete(SupplierDTO item)
		{
			Supplier supplier = Supplier.SelectUsingPK(item.SupplierId);
			if (supplier == null) return false;
			supplier.Delete();
			supplier.Persist();
			return true;
		}

		#endregion

	}
}
